
package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.HighRequest;
import com.sasis.model.PlaneState;
import com.sasis.dao.PlaneStateDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class PlaneStateDaoiBatis extends BaseDaoiBATIS implements PlaneStateDao {

    /**
     * @see com.sasis.dao.PlaneStateDao#getPlaneStates(com.sasis.model.PlaneState)
     */
    public List getPlaneStates(final PlaneState planeState) {
          return getSqlMapClientTemplate().queryForList("getPlaneStates", planeState);
    }

    public List selectPlaneStates(final PlaneState planeState) {
		return getSqlMapClientTemplate().queryForList("selectPlaneStates",
				planeState);
	}
    
    /**
     * @see com.sasis.dao.PlaneStateDao#getPlaneState(Integer id)
     */
    public PlaneState getPlaneState(Integer id) {
        PlaneState planeState = (PlaneState) getSqlMapClientTemplate().queryForObject("getPlaneState", id);

        if (planeState == null) {
            throw new ObjectRetrievalFailureException(PlaneState.class, id);
        }

        return planeState;
    }

    /**
     * @see com.sasis.dao.PlaneStateDao#savePlaneState(PlaneState planeState)
     */    
    public void savePlaneState(final PlaneState planeState) {
        Integer id = planeState.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addPlaneState", planeState);
        } else {
            getSqlMapClientTemplate().update("updatePlaneState", planeState);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(PlaneState.class, id);
        }
    }

    /**
     * @see com.sasis.dao.PlaneStateDao#removePlaneState(Integer id)
     */
    public void removePlaneState(Integer id) {
        getSqlMapClientTemplate().update("deletePlaneState", id);
    }
}
